/*
 * @lc app=leetcode.cn id=2024 lang=cpp
 *
 * [2024] 考试的最大困扰度
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <stdlib>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
//滑动窗口法
    int countChar(string answerKey, int k,char ch) {
        int n = answerKey.length();
        int left = 0,right = 0;
        //count记录出现的不是ch字符的数量，若此数量多余k，则左窗口右移
        //ret记录窗口长度
        int count = 0,ret = 0;
        for(;right < n;right++) {
            count += answerKey[right] != ch;
            while(count > k) {
                count -= answerKey[left] != ch;
                left++;
            }
            ret = max(right-left+1,ret);
        }
        return ret;
    }
    int maxConsecutiveAnswers(string answerKey, int k) {
        return max(countChar(answerKey,k,'T'),countChar(answerKey,k,'F'));
    }
};
// @lc code=end

